package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TMajorPlan;
import com.ruoyi.system.service.ITMajorPlanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 专业考试时间计划Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@Controller
@RequestMapping("/system/plan")
public class TMajorPlanController extends BaseController
{
    private String prefix = "system/plan";

    @Autowired
    private ITMajorPlanService tMajorPlanService;

    @RequiresPermissions("system:plan:view")
    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询专业考试时间计划列表
     */
    @RequiresPermissions("system:plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TMajorPlan tMajorPlan)
    {
        startPage();
        List<TMajorPlan> list = tMajorPlanService.selectTMajorPlanList(tMajorPlan);
        return getDataTable(list);
    }

    /**
     * 导出专业考试时间计划列表
     */
    @RequiresPermissions("system:plan:export")
    @Log(title = "专业考试时间计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TMajorPlan tMajorPlan)
    {
        List<TMajorPlan> list = tMajorPlanService.selectTMajorPlanList(tMajorPlan);
        ExcelUtil<TMajorPlan> util = new ExcelUtil<TMajorPlan>(TMajorPlan.class);
        return util.exportExcel(list, "专业考试时间计划数据");
    }

    /**
     * 新增专业考试时间计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专业考试时间计划
     */
    @RequiresPermissions("system:plan:add")
    @Log(title = "专业考试时间计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TMajorPlan tMajorPlan)
    {
        return toAjax(tMajorPlanService.insertTMajorPlan(tMajorPlan));
    }

    /**
     * 修改专业考试时间计划
     */
    @RequiresPermissions("system:plan:edit")
    @GetMapping("/edit/{majorPlanId}")
    public String edit(@PathVariable("majorPlanId") Long majorPlanId, ModelMap mmap)
    {
        TMajorPlan tMajorPlan = tMajorPlanService.selectTMajorPlanByMajorPlanId(majorPlanId);
        mmap.put("tMajorPlan", tMajorPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存专业考试时间计划
     */
    @RequiresPermissions("system:plan:edit")
    @Log(title = "专业考试时间计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TMajorPlan tMajorPlan)
    {
        return toAjax(tMajorPlanService.updateTMajorPlan(tMajorPlan));
    }

    /**
     * 删除专业考试时间计划
     */
    @RequiresPermissions("system:plan:remove")
    @Log(title = "专业考试时间计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tMajorPlanService.deleteTMajorPlanByMajorPlanIds(ids));
    }

    @Log(title = "替代课程考试时间计划导入", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:plan:import")
    @PostMapping("/importData")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TMajorPlan> util = new ExcelUtil<TMajorPlan>(TMajorPlan.class);
        List<TMajorPlan> userList = util.importExcel(file.getInputStream());
        String message = tMajorPlanService.importData(userList, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    @RequiresPermissions("system:plan:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<TMajorPlan> util = new ExcelUtil<TMajorPlan>(TMajorPlan.class);
        return util.importTemplateExcel("替代课程考试时间计划导入模版");
    }
}
